package model;

import java.io.BufferedReader;
import java.io.IOException;

import applet.molecule.Atom;

/**
 * The model of hexanol molecule.
 * 
 * @see model.moleculeModel
 */
public class HexanolMolecule extends MoleculeModel {

	/** the number of atoms in hexanol molecule */
	public static final int ATOM_NUM = 8;

	/**
	 * Parse configuration file and generate the hexanol molecule model.
	 * 
	 * @param reader the buffered reader accesses to configuration file.
	 * 
	 * @return hexanol molecule model
	 * 
	 * @throws IOException if there is some IO exception occur
	 */
	public static HexanolMolecule parseHexanol(BufferedReader reader) throws IOException {
		HexanolMolecule hexanol = new HexanolMolecule();
		hexanol.type = MoleculeType.HEXANOL;
		
		// parse 'O'
		String line = reader.readLine();
		String[] split = line.trim().split("[\\s]+");
		hexanol.list.add(new Atom("HO", Float.parseFloat(split[0]), Float
				.parseFloat(split[1]), Float.parseFloat(split[2])));
		
		// parse 'C'
		final int totalC = 6;
		for(int i = 0; i<totalC; i++){
			line = reader.readLine();
			split = line.trim().split("[\\s]+");
			hexanol.list.add(new Atom("C", Float.parseFloat(split[0]), Float
					.parseFloat(split[1]), Float.parseFloat(split[2])));
		}
		
		// parse 'H'
		line = reader.readLine();
		split = line.trim().split("[\\s]+");
		hexanol.list.add(new Atom("H", Float.parseFloat(split[0]), Float
				.parseFloat(split[1]), Float.parseFloat(split[2])));
		
		return hexanol;
	}

}
